contents_arch = [ ["ARCH_X86", "-Wall -Iinclude -nostdlib -nostartfiles -ffreestanding -std=gnu99 -fno-stack-protector -nostdlib -nostdinc -fno-builtin -nodefaultlibs", "-Tarch/x86/link.ld", "-felf", "arch/x86/boot.o arch/x86/dt.o arch/x86/clock.o arch/x86/timer.o arch/x86/io.o arch/x86/arch.o arch/x86/kvideo.o arch/x86/kkeyb.o arch/x86/calls.o", "arch/x86/kernel", "gcc", "as", "ld", "nasm", ["BIT32", "ARCH \"x86\""]] ]

contents =  [ 	["TRACE", ["ETRACE"], "trace.o"], 
				["SMP", ["SMP"], "" ],
				["VFS", ["VFS"], "" ], 
				["DEV", ["DEV"], "" ], 
				["DRV", ["DRV"], "" ],
				["VESA", ["VESA"], "drivers/video/vesa/vesa.o" ],
				["PCI", ["PCI"], "drivers/bus/pci/pci.o" ],
				["RS232", ["RS232"], "drivers/net/rs232/rs232.o" ],
				["SHELL", ["SHELL", "PIGSH"], "shell/shell.o"],
				["PORK_GUI", ["PORK_GUI"], "../app/porkgui/render.o ../app/porkgui/pork_gui.o ../app/porkgui/env.o"] 
			]

#["PORK_GUI"
#["GLPIG"

ls = open("config", "r").read().split("\n")
makefile = "include Makefile.com\n\n"
config = "#ifndef __CONFIG_H\n#define __CONFIG_H\n\n"
sources = "SOURCES=$(OBJS) "
for x in ls:
	# Arch?
	for i in contents_arch:
		if i[0] == x:
			makefile += "CFLAGS="+i[1]+"\n"
			makefile += "LDFLAGS="+i[2]+"\n"
			makefile += "ASFLAGS="+i[3]+"\n\n"
			makefile += "OBJS="+i[4]+"\n"
			makefile += "KERNEL="+i[5]+"\n\n"
			makefile += "TCC="+i[6]+"\n"
			makefile += "TAS="+i[7]+"\n"
			makefile += "TLD="+i[8]+"\n"
			makefile += "TASM="+i[9]+"\n\n\n"
			config += "#define "+i[0]+"\n"
			for j in i[10]:
				config += "#define "+j+"\n"
			
	for i in contents:
		if i[0] == x.split("=")[0]:
			for j in i[1]:
				config += "#define "+j+"\n"
			
			sources += " " + i[2]
			
			
makefile += sources+" $(COM_O)\n\n"
makefile += "all: $(SOURCES) link\n"
makefile += ".s.o:\n"
makefile += "\t$(ASM) $(ASFLAGS) $<\n"
makefile += "link:\n"
makefile += "\t$(LD) $(LDFLAGS) -o arch/x86/kernel $(SOURCES)\n\n"
makefile += "clean:\n\trm $(SOURCES)\n"
config += "\n\n#endif\n"

f = open("include/config.h", "w")
f.write(config)
f.close()

f = open("Makefile", "w")
f.write(makefile)
f.close()

	
	
			
	
